package com.qishenyuan.competition.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@Component
public class AuthTokenInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler){
        // 获取请求头中的 token
        String token = request.getHeader("X-AUTH-TOKEN");
        if (token != null && !token.isEmpty()) {
            String requestUri = request.getRequestURI();
            log.info("Request URL: {}, X-AUTH-TOKEN: {}", requestUri, token);
        }
        // 不管有没有 token，都放行
        return true;
    }
}
